######## FOR FIGURE S1 IN THE SI:

rm(list=ls())
library(foreign)
library(ggplot2) 
library(gridExtra)
library(knitr)
library(grid)
library(dplyr)
library(forcats)
#install.packages("extrafont")
library(extrafont)
#install.packages("performance")
library("performance")
library("see")
library("haven")

setwd("~/Dropbox/Side projects/BET HOUSES PROJECT/data/Gambling_Replication_Materials/Data")
setwd("~/Dropbox/EUI/BET HOUSES PROJECT/data/Gambling_Replication_Materials/Estimates")

# First theme result
theme_results <- theme_bw(base_size = 15) +
  theme(text=element_text(family="Times",
                          size = 15),
        axis.text.x = element_text(size = 15, color = "black"),
        axis.text.y = element_text(size = 15, color = "black",angle=0),
        axis.title.y = element_text(size = 18, color = "black"),
        axis.title.x = element_text(size = 18, color = "black"),
        legend.position = "top",
        legend.key.size = unit(1.2, "cm"),
        legend.text = element_text(size = 18),
        legend.title = element_text(size = 18),
        panel.grid.major.y = element_blank(),
        panel.grid.minor.y = element_blank(),
        strip.text.y.right = element_text(angle = 0)
  )

######## Commuting patterns for histogram:

tohist <- read_dta("movilidad_merged_1503.dta")
#tohist$distancia <- as.numeric(tohist$distancia)

figureS1<-ggplot(tohist, aes(x=distancia_viaje, y=..density..)) + 
  geom_histogram(binwidth = 0.2, color = "white", fill = "black", alpha = .7) +
  geom_vline(aes(xintercept = 0.503),linetype = 5, color = "blue") +
  annotate("text", x = .85, y = 1.125, label = "Average distance", size = 8, color = "blue", family = "Times") +
  ylab("Density") +
  xlab("Madrid's students commuting distance in km.") +
  theme_results 
  #ggsave(file="commuting_figure.png", width = 25, height = 20, units = "cm") #saves g

figureS1
